import pygame


class Player(pygame.sprite.Sprite):
    def __init__(self,img, dims, size, position):
        super().__init__()
        self.image = img
        self.position = position
        self.dims = dims
        self.size = size
        self.rect = self.image.get_rect()
        self.rect.center = (position)
        self.speed = 5

    def move(self, direction):
        if direction == 'up':
            self.rect.y -= self.speed
            if self.rect.y < 0: self.rect.y = 0
        if direction == 'down':
            self.rect.y += self.speed
            if self.rect.y > self.dims[1] - self.rect.height: self.rect.y = self.dims[1] - self.rect.height
        if direction == 'left':
            self.rect.x -= self.speed
            if self.rect.x < 0: self.rect.x = 0
        if direction == 'right':
            self.rect.x += self.speed
            if self.rect.x > self.dims[0] - self.rect.width: self.rect.x = self.dims[0] - self.rect.width

    def draw(self, screen):
        screen.blit(self.image, self.rect)
